/*
 * @Author: Qimu
 * @Date: 2020-04-20 22:23:10
 * @LastEditors: Qimu
 * @LastEditTime: 2020-07-16 01:17:22
 * @Description: file content
 * @FilePath: \vue-admin-koa2\koa2_api\routes\api\admin.js
 */
const config = require('../../module/config/config');
const router = require('koa-router')();
const menu = require('../../controllers/menu');
const role = require('../../controllers/role');
const admin = require('../../controllers/admin');
const user = require('../../controllers/user');
const carousel = require('../../controllers/carousel');
const lesson = require('../../controllers/lesson');
const article = require('../../controllers/article');
const checkToken = require('../../module/middleware/checkToken').admin()// 引入checkToken中间件
const upload = require('../../module/middleware/upload')// 引入upload中间件
const refreshToken = require('../../module/middleware/refreshToken').admin()// 引入refreshToken中间件
// 为router配置路由前缀 
router.prefix(`${config.app.baseApi}`);// 前缀: /api
/* HTTP动词
    GET 查询  POST 新建  PUT 替换F
    PATCH  更新部分属性
    DELETE 删除指定ID的文档
*/
//admin 后台后端接口
router
  //管理员模块
  .post('/admin/adminLogin', admin.adminLogin)  //管理员登录                        
  .post('/admin/setAdmin', admin.setAdmin) //新增管理员信息
  .post('/admin/uploadAvatar', checkToken, upload.single('file'), admin.uploadAvatar) //管理员头像
  .get('/admin/listAdmin', checkToken, admin.listAdmin) //管理员列表
  .patch('/admin/updateAdmin', checkToken, admin.updateAdmin) //修改管理员状态
  .put('/admin/putAdmin', checkToken, admin.putEditAdmin) //提交编辑管理员
  .delete('/admin/deleteAdmin/:id', checkToken, admin.deleteAdmin) //删除选中管理员  
  .post('/users/refreshToken', refreshToken) //刷新用户token 
  .post('/logout', checkToken, admin.logout) //用户登出（前台删除token即可）

  //菜单模块
  .post('/menu/set', checkToken, menu.setMenu) //一级菜单设置
  .post('/submenu/set', checkToken, menu.setSubmenu) //二级菜单设置
  .get('/menu/list', checkToken, menu.listMenu) //菜单列表
  .patch('/menu/showMenu', checkToken, menu.showEditMenu)  //编辑菜单
  .put('/menu/putMenu', checkToken, menu.putEditMenu) //提交编辑菜单
  .delete('/menu/deleteMenu/:level/:id', checkToken, menu.deleteMenu) //删除选中菜单                      

  //角色模块
  .post('/role/setRole', checkToken, role.setRole) //新增角色信息
  .get('/role/listRole', checkToken, role.listRole) //角色列表
  .patch('/role/updateRole', checkToken, role.updateRole) //修改角色状态
  .put('/role/putRole', checkToken, role.putEditRole) //提交编辑角色
  .delete('/role/deleteRole/:id', checkToken, role.deleteRole) //删除选中角色  

  //用户模块
  .post('/user/setUser', user.setUser) //新增用户注册(前台前端使用)
  .get('/user/listUser', checkToken, user.listUser) //用户列表

  //图片模块
  .post('/carousel/set', checkToken, carousel.setCarousel) //轮播设置
  .get('/carousel/list', checkToken, carousel.listCarousel) //轮播列表

  //课程列表
  .post('/lesson/set', checkToken, lesson.setLesson)
  .get('/lesson/list', checkToken, lesson.listLesson)

  //文章模块
  .post('/articles/setArticleCategory', checkToken, article.setArticleCategory)  //文章分类模块
  .get('/articles/articleCategoryList', checkToken, article.getArticleCategoryList) //获取文章分类列表
  .put('/articles/putArticleCategory', checkToken, article.putEditArticleCategory) //提交编辑文章分类
  .delete('/articles/deleteArticleCategory/:id', checkToken, article.deleteArticleCategory) //删除选中文章分类
  .post('/articles/addArticle', checkToken, article.addArticle)  //新增文章内容
  .get('/articles/articleList', article.getArticleList) //获取文章列表
  .get('/articles/articleDetail/:id', checkToken, article.getArticleDetail) //文章详情

// .post('/tags', checkToken, T.createTag)                                  //创建标签
// .get('/tags', T.getAllTags)                                    //获取所有标签
// .patch('/tags/:id', checkToken, T.modifyTag)                                //修改单个标签
// .delete('/tags/:id', checkToken, T.deleteTag)                               //删除单个标签


// .get('/me', M.getMeInfo)                                     //获取个人信息
// .patch('/me', checkToken, M.modifyMeInfo);                   //更改个人信息

// const T = require('../controllers/tag.js');
// const U = require('../controllers/user.js');
// const M = require('../controllers/me.js'); 

// .post('/modifyUser', checkToken, U.updateUserMes)   //更改用户信息
// .post('/modifyPwd', checkToken, U.resetPwd)         //更改用户密码
exports = module.exports = router;


